from math import *

def thorus(x,y,z,r,R):
	return (sqrt(x*x+y*y) - R)**2 + z*z < r*r

def thoruses(x,y,z):
	return thorus(x,y,z,0.1,0.3) or thorus(x+0.3,z,y,0.1,0.3)

def somestaff(x,y,z):
	return thoruses(x*y,y*z,z*x)


def eightspower(x,y,z):
	r=(x*x+y*y+z*z)**4
	theta=atan2(x,y)
	phi=atan2(sqrt(x*x+y*y),z)
	return r*cos(8*theta)*cos(8*phi),r*sin(8*theta)*cos(8*phi),r*sin(8*phi)


def mandelbulb(x,y,z):
	x2,y2,z2=x,y,z
	for i in range(5):
		if x2*x2+y2*y2+z2*z2 > 2:
			return False
		new=eightspower(x2,y2,z2)
		x2=new[0]+x
		y2=new[1]+y
		z2=new[2]+z
	return True	
